/**
 * File    : LabelValueModelProcessor.java
 * Created : 2009-3-30
 * By      : LuHuiguo
 */
package com.luhuiguo.cms.client.widget;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelProcessor;

/**
 * @author LuHuiguo
 * @version $Id: LabelValueModelProcessor.java 163 2010-05-10 15:36:28Z luhuiguo@gmail.com $
 */
public class LabelValueModelProcessor<M extends ModelData> extends ModelProcessor<M> {

    public static final String DISPLAY = "display";

    private String labelField = LabelValue.LABEL;

    private String valueField = LabelValue.VALUE;

    private String displayField = DISPLAY;

    /**
     * 
     */
    public LabelValueModelProcessor() {
        super();
    }

    /**
     * @param labelField
     * @param valueField
     */
    public LabelValueModelProcessor(String labelField, String valueField) {
        super();
        this.labelField = labelField;
        this.valueField = valueField;
    }

    /**
     * @param labelField
     * @param valueField
     * @param displayField
     */
    public LabelValueModelProcessor(String labelField, String valueField, String displayField) {
        super();
        this.labelField = labelField;
        this.valueField = valueField;
        this.displayField = displayField;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.extjs.gxt.ui.client.data.ModelProcessor#prepareData(com.extjs.gxt.ui.client.data.ModelData)
     */
    @Override
    public M prepareData(M model) {

        model.set(displayField, model.get(valueField) + " - " + model.get(labelField));
        return model;

    }

}
